package com.tom.demo.web.common;

import com.tom.demo.common.entity.FileResponse;
import com.tom.demo.common.response.Result;
import com.tom.demo.service.common.FileService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

@Api(tags = {"文件管理"})
@RestController
@RequestMapping("/common")
public class FileController {
    @Resource
    private FileService fileService;
    /**
     * 单文件上传
     * @param file
     * @return
     */
    @PostMapping("/uploadFile")
    @ApiOperation(value = "文件上传")
    public Result uploadFile(@RequestParam("file") MultipartFile file, HttpServletRequest httpServletRequest){
        FileResponse fileResponse = fileService.storageFile(file,httpServletRequest);
        return Result.success(fileResponse);
    }
}
